<template>
  <el-dialog
    class="banner-product-container"
    title="设置轮播图"
    :visible="bannerDialogShow"
    width="60%"
    center
    top="0vh"
    :append-to-body="true"
    :close-on-click-modal="false"
    @close="close"
  >

    <div class="center">
      <div class="banner">
        <span>轮播图</span>
        <div class="banner-warp">
          <!-- 轮播图 -->
          <el-upload
            action="https://jsonplaceholder.typicode.com/posts/"
            list-type="picture-card"
            :on-preview="handlePictureCardPreview"
            :on-remove="handleRemove"
          >
            <i class="el-icon-plus" />
          </el-upload>
          <el-dialog :visible.sync="dialogVisible">
            <img width="100%" :src="dialogImageUrl" alt="">
          </el-dialog>
        </div>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="btnOk">确定</el-button>
      </span>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'BannerProduct',
  props: {
    bannerDialogShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      dialogImageUrl: '',
      dialogVisible: false // 预览弹层
    }
  },
  methods: {
    close() {
      this.$emit('update:bannerDialogShow', false)
    },
    btnOk() {
      this.close()
    },
    // 删除图片事件
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    // 图片预览
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    }
  }
}
</script>

<style lang="scss" scoped>
.banner-product-container {
    ::v-deep .el-dialog {
        height: 100vh;
    }
    span {
      margin-right: 10px;
      margin-top: 10px
    }
    ::v-deep .el-dialog__body {
      display: flex;
    }
    ::v-deep .el-upload--picture-card {
      display: flex;
      justify-content: center ;
      align-items: center;
      width: 100px;
      height: 100px;
      &:hover {
        background-color: #ebedf0;
      }
    }
    .el-upload-list {
      display: flex;
      align-items: center;
    }
    ::v-deep .el-upload-list__item {
      width: 100px;
      height: 100px
    }
    .banner {
      display: flex;
    }
}
</style>
